<%@page import="java.util.ArrayList"%>
<%@page import="com.liferay.portal.kernel.dao.search.SearchContainer"%>
<%@page import="com.caresms.service.Sms_MasterLocalServiceUtil"%>
<%@page import="com.caresms.service.Category_MasterLocalServiceUtil"%>
<%@page import="com.caresms.model.Category_Master"%>
<%@page import="java.util.List"%>

<%@page import="com.caresms.model.Sms_Master"%>

<%@include file="/init.jsp"%>

<%@page import="javax.portlet.PortletURL"%>
<portlet:actionURL name="abc" var="processURL"></portlet:actionURL>


<script
	src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"
	type="text/javascript"></script>


<form action="<%=processURL.toString()%>" method="post"
	onsubmit="setHiddenParam()" name="autocompleteform"
	id="autocompleteform">
	<div id="myAutoComplete" style="float: left;"></div>
	<input type="hidden" name="keyword" id="keyword" value="" /> <input
		type="submit" value="Go">
	<h2 id="slogan">World's No1. SMS Search Engine</h2>
</form>
<script type="text/javascript" charset="utf-8">
$(function() {
	   $('autocompleteform').each(function() {
	       $('input').keypress(function(e) {
	           // Enter pressed?
	           if(e.which == 10 || e.which == 13) {
	               this.autocompleteform.submit();
	           }
	       });

	      
	   });
	});
	 
AUI().use('aui-autocomplete', function(A) {
var dataSource = new A.DataSource.IO(
    {
        source: '<portlet:resourceURL />'
    }
);

var autocomplete = new A.AutoComplete(
    {
        dataSource: dataSource,
        delimChar: '',
        contentBox: '#myAutoComplete',
        matchKey: 'key',
        maxResultsDisplayed:20,
        minQueryLength:2,
        schema: {
            resultListLocator: 'response',
            resultFields: ['key']
        },
        uniqueName:'keyword',
        schemaType:'json',
        typeAhead: false,
        cssClass: 'ac_input'
    });

autocomplete.generateRequest = function(query) {
    return {
        request: '&q=' + query
    };

};
autocomplete.render();
$('#myAutoComplete').find('input').val(document.autocompleteform.keyword.value);
});
function setHiddenParam() {
	
	document.autocompleteform.keyword.value = $('#myAutoComplete').find('input').val();
	
	return true;
}

</script>
<div id="leftcatdiv">
<%
List<Category_Master> list = Category_MasterLocalServiceUtil
.getCategory_Masters(-1, -1);
%>
<liferay-ui:search-container delta="10"
		emptyResultsMessage="No Results Found">
		<liferay-ui:search-container-results total="<%=list.size()%>"
			results="<%=list%>" />
		<liferay-ui:search-container-row modelVar="cat"
			className="com.caresms.model.impl.Category_MasterImpl">
			<portlet:actionURL var="catDiaplayURL" name="catDisplay">
	<portlet:param name="catid" value="<%=String.valueOf(cat.getCatId()) %>"/>
	</portlet:actionURL>
			<liferay-ui:search-container-column-text name='Category Name' href="<%=catDiaplayURL %>">
			<%=cat.getCatName() %>&nbsp;&nbsp;&#91;<%=cat.getCountsms() %>&#93;
			</liferay-ui:search-container-column-text>
			
		</liferay-ui:search-container-row>
		<liferay-ui:search-iterator searchContainer="<%=searchContainer%>"
			paginate="<%=true%>" />



	</liferay-ui:search-container>
</div>
<div id="catDisplay">

	<%
		if (request.getAttribute("catDisplay") != null) {
			List<Sms_Master> sm = (List<Sms_Master>) request
					.getAttribute("catDisplay");
	%>
	<liferay-ui:search-container delta="20"
		emptyResultsMessage="No Results Found">
		<liferay-ui:search-container-results total="<%=sm.size()%>"
			results="<%=sm%>" />
		<liferay-ui:search-container-row modelVar="sms"
			className="com.caresms.model.impl.Sms_MasterImpl">
			<portlet:renderURL var="smsexpandURL">
				<portlet:param name="jspPage" value="/Search/view.jsp" />
				<portlet:param name="search"
					value='<%=String.valueOf(sms.getSmsId())%>' />
				<portlet:param name="keyword"
					value='<%=String.valueOf(sms.getSmsContent()
									.substring(0, 20))%>' />
			</portlet:renderURL>

			<liferay-ui:search-container-column-text name='SMS Content'>
				<%
					if (sms.getSmsContent().length() > 25) {
				%>
				<p id="smsheader"><%=sms.getSmsContent().substring(0, 25)%>....
				</p>
				<br />
				<%
					}
				%>
				<p id="smsbody"><%=sms.getSmsContent()%></p>
				<br />
				<p id="smsfooter">
					<a href="<%=smsexpandURL%>" target="_blank"><img
						src="<%=request.getContextPath()%>/openicon.jpg"></a>SMS Size :<%=sms.getSms_chars_Size()%>
				</p>


			</liferay-ui:search-container-column-text>

		</liferay-ui:search-container-row>
		<liferay-ui:search-iterator searchContainer="<%=searchContainer%>"
			paginate="<%=true%>" />
	</liferay-ui:search-container>
	<%
		}
	%>
</div>